package org.argus.job.server.system.management.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.argus.job.common.enums.InstanceStatus;
import org.argus.job.server.system.domain.InstanceInfoEntity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author 刘文/Cliff Liu
 * @Date 2024/8/29
 */
public interface InstanceInfoMapper extends BaseMapper<InstanceInfoEntity> {

    List<Long> findByJobIdInAndStatusIn(@Param("jobIds") List<Long> jobIds,
        @Param("statuses") List<InstanceStatus> statuses);

    int updateStatusChangeInfoByInstanceIdAndStatus(@Param("instanceInfo") InstanceInfoEntity instanceInfo,
        @Param("originStatus") InstanceStatus originStatus);

    long countByJobIdAndStatusIn(@Param("jobId") Long jobId,
        @Param("instanceStatuses") ArrayList<InstanceStatus> instanceStatuses);

    void update4TriggerFailed(@Param("instanceId") Long instanceId, @Param("instanceStatus") InstanceStatus instanceStatus,
        @Param("actualTriggerTime") long actualTriggerTime, @Param("finishedTime") long finishedTime,
        @Param("taskTrackerAddress") String taskTrackerAddress, @Param("result") String result,
        @Param("modifyTime") Date modifyTime);

    void update4TriggerSucceed(@Param("instanceId") Long instanceId, @Param("status") InstanceStatus status,
        @Param("actualTriggerTime") long actualTriggerTime, @Param("taskTrackerAddress") String taskTrackerAddress,
        @Param("modifyTime") Date modifyTime, @Param("oldStatus") InstanceStatus oldStatus);

}
